package com.tmxk.jdbc03;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class SingletonLazyTest {
    // 多线程使用场景
    // 使用线程池模拟多线程场景下,懒汉式获取单例
//        int corePoolSize,
//        int maximumPoolSize,
//        long keepAliveTime,
//        TimeUnit unit,
//        BlockingQueue<Runnable> workQueue
    // 线程核心数量
    static final int corePoolSize = 30;
    static final ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(corePoolSize,corePoolSize,0,
            TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>());

    public static void main(String[] args) {

        for (int i = 0; i < 30 ; i++) {
            poolExecutor.submit(()->{
                System.out.println(SingletonLazy.getInstance());
            });
        }
        // 关闭线程池
        //poolExecutor.shutdown();
    }
}
